package com.test.mooan.labama.demo.data

import android.content.Context
import android.os.Build
import com.test.mooan.labama.demo.util.GeneralUtil
import com.test.mooan.labama.demo.util.HardwareUtil
import com.test.mooan.labama.demo.util.NetworkUtil
import com.test.mooan.labama.demo.util.gzipString
import com.google.gson.Gson

class HardwareInfo(val context: Context) {

    fun fetch(): String? {
        return try {
           val data = hashMapOf<String, Any>().apply {
                put("operatingSystem", "ANDROID")
                put("model", Build.MODEL.toString())
                put("serial", Build.SERIAL.toString())
                put("productionDate", Build.TIME.toString())
                put("sdkVersion", Build.VERSION.SDK_INT.toString())
                put("phoneType", GeneralUtil.getPhoneType(context))
                put("versionCode", GeneralUtil.getVersionCode(context))
                put("versionName", GeneralUtil.getVersionName(context))
                put("androidId", GeneralUtil.getAndroidID(context))
                put("telephony", GeneralUtil.getSimOperatorName(context))
                put("isVpn", NetworkUtil.getVpnState(context))
                put("isProxyPort", NetworkUtil.getIsWifiProxy())
                put("isDebug", GeneralUtil.getIsDebug(context))
                put("simState", GeneralUtil.getSimCardState(context))
                put("root", HardwareUtil.getIsRoot())
                put("physicalSize", HardwareUtil.getPhySicalSize(context))
                put("displayLanguage", GeneralUtil.getDisplayLanguage())
                put("iso3Language", GeneralUtil.getIso3Language())
                put("iso3Country", GeneralUtil.getIso3Country())
                put("networkOperatorName", GeneralUtil.getSimOperatorName(context))
                put("networkType", GeneralUtil.getNetworkType(context))
                put("timeZoneId", GeneralUtil.getTimeZoneId())
                put("elapsedRealtime", GeneralUtil.getElapsedRealtime())
                put("sensorList", HardwareUtil.getSensorList(context))
                put("lastBootTime", GeneralUtil.getLastBootTime())
                put("rootJailbreak", HardwareUtil.getIsRoot())
                put("keyboard", HardwareUtil.getKeyboard(context))
                put("isSimulator", HardwareUtil.getIsSimulator())
                put("dbm", HardwareUtil.getMobileDbm(context)) //
                put("phoneNumber", "")
            }
            Gson().toJson(data).trim().gzipString()

        } catch (e: java.lang.Exception) {
            null
        }
    }
}